//
//  CustomerMessageCell.m
//  New_Runway
//
//  Created by mack on 2018/2/9.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "CustomerMessageCell.h"
#import "CustomerEditRemarkVC.h"

@interface CustomerMessageCell ()
@property (weak, nonatomic) IBOutlet UIImageView *header;
@property (weak, nonatomic) IBOutlet UILabel *nickName;
@property (weak, nonatomic) IBOutlet UIButton *callBtn;

@property (weak, nonatomic) IBOutlet UILabel *lastActiveTime;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *distance;
@property (weak, nonatomic) IBOutlet UIButton *remarkBtn;
@end

@implementation CustomerMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.header.layer.masksToBounds = YES;
    self.header.layer.cornerRadius = 30;
    self.header.layer.borderWidth = 0.5;
    self.header.layer.borderColor = UIColorHex(0xbfbfbf).CGColor;


}
-(void)setInfoModel:(CustomerInfoModel *)infoModel{
    _infoModel = infoModel;
    [self.header sd_setImageWithURL:[NSURL URLWithString:infoModel.result.customerHeadImage]];
    self.nickName.text = infoModel.result.customerNickName;
    if (infoModel.result.customerMobile) {
        [self.callBtn setTitle:infoModel.result.customerMobile forState:UIControlStateNormal];
        self.callBtn.hidden = NO;
        self.distance.constant = 30;
        [self.callBtn setImage:[UIImage imageNamed:@"phone-2"] forState:UIControlStateNormal];


    }else{
        [self.callBtn setTitle:@"" forState:UIControlStateNormal];
        [self.callBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        self.callBtn.hidden = YES;
        self.distance.constant = -30;
    }
    if (infoModel.result.customerRemark) {
        [self.remarkBtn setTitle:infoModel.result.customerRemark forState:UIControlStateNormal];
    }else{
        [self.remarkBtn setTitle:@"备注" forState:UIControlStateNormal];

    }
    self.lastActiveTime.text = [NSString stringWithFormat:@"最近活跃时间： %@",infoModel.result.createTime];
    
    
}
- (IBAction)callCustomer:(id)sender {
    
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_infoModel.result.customerMobile];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self addSubview:callWebview];
}
- (IBAction)editRemark:(id)sender {
    CustomerEditRemarkVC *remarkVc = [[CustomerEditRemarkVC alloc] init];
    remarkVc.block = ^(NSString *remark) {
        [self.remarkBtn setTitle:remark forState:UIControlStateNormal];
    };
    remarkVc.customerId = self.customerId;
    remarkVc.reStr = _infoModel.result.customerRemark;
    [self.nav pushViewController:remarkVc animated:YES];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
